package taskmon

import (
	redisdk "github.com/darwinOrg/go-redis"
	"github.com/gin-gonic/gin"
	"github.com/hibiken/asynqmon"
)

type customRedisClientOpt struct{}

func (*customRedisClientOpt) MakeRedisClient() any {
	return redisdk.GetUniversalClient()
}

func RegisterRouter(e *gin.Engine, rootPath string) {
	if redisdk.GetUniversalClient() == nil {
		panic("redis client is nil")
	}

	mon := asynqmon.New(asynqmon.Options{
		RootPath:     rootPath,
		RedisConnOpt: &customRedisClientOpt{},
	})

	e.Any(rootPath+"/*", gin.WrapH(mon))
}
